package cn.jbolt.ec.retailer;

import cn.jbolt.base.JBoltBaseController;
import com.alibaba.fastjson.JSONObject;
import com.jfinal.aop.Inject;

/**
 * @author xieguo
 */
public class EcRetailerController extends JBoltBaseController {
    @Inject
    RetailerService service;

    @Inject
    RetailerTypeService typeService;

    @Inject
    RetailerChargeBonusService retailerChargeBonusService;


    /**
     * 获取所有商家类别
     */
    public void get_retailer_class(){
        renderJson(typeService.get_retailer_class());
    }

    /**
     * 分页/按姓名搜索商家
     * @param pageNumber
     * @param pageSize
     * @param pattern
     */
    public void retailer_info(int pageNumber,int pageSize,Integer type_id,String pattern){
        if (type_id!=null&&pageNumber>0&&pageSize>0){
            renderJson(service.retailer_info(pageNumber, pageSize,type_id,pattern));
        }else {
            renderText("参数异常");
        }

    }



    /**
     * 根据商家id获取信息
     * @param id
     */
    public void retailer_info_by_id(int id){
        if (id>0){
            renderJson(service.retailer_info_by_id(id));
        }else {
            renderText("参数异常");
        }

    }

    /**
     * 获取商家订单信息
     * @param retailer_id
     * @param status
     * @param pageNumber
     * @param pageSize
     */
    public void retailer_order_info(int retailer_id,int status,int pageNumber,int pageSize){
        if (retailer_id>0&&status>0&&pageNumber>0&&pageSize>0){
            renderJson(service.retailer_order_info(retailer_id, status, pageNumber, pageSize));
        }else {
            renderText("参数异常");
        }

    }

    /**
     * 商家确认送货
     * @param openSession
     * @param orders
     */
    public void confirm(String openSession, String orders){
        JSONObject jo1=new JSONObject();
        if (null!=getSessionAttr(openSession+"_retailer_id")){
            JSONObject jo=new JSONObject();

            if(service.confirm(getSessionAttr(openSession+"_retailer_id"), orders)>0){
                jo.put("code",0);
                jo.put("msg","已确认发货");
                renderJson(jo);
            }else {
                jo.put("code",1);
                jo.put("msg","确认失败");
                renderJson(jo);
            }
        }else {
            jo1.put("code",1);
            jo1.put("msg","无效Session");
            renderJson(jo1);
        }

    }



    /**
     * 获取附近门店
     * @param pageNumber
     * @param pageSize
     * @param pattern
     */
    public void get_near(int pageNumber,int pageSize,String pattern){
        if (pageNumber>0&&pageSize>0){
            renderJson(service.get_near(pageNumber, pageSize, pattern));
        }else {
            renderText("参数异常");
        }

    }


    /**
     * 充值送券或余额的策略
     * @param retailer_id
     */
    public void get_charge_bonus(int retailer_id){
        if (retailer_id>0){
            renderJson(retailerChargeBonusService.get_charge_bonus(retailer_id));
        }else {
            renderText("参数异常");
        }

    }



}
